package com.prodog.commonmodule.prop.caculate.factory;

import cn.hutool.core.util.ReflectUtil;
import com.prodog.commonmodule.prop.caculate.handler.MonsterPropHandler;
import com.prodog.commonmodule.prop.caculate.handler.ObjPropHandler;
import com.prodog.commonmodule.prop.caculate.handler.RolePropHandler;
import com.prodog.gamemodule.gameworld.monster.entity.MonsterProp;
import com.prodog.usermodule.role.entity.RoleProp;

import java.util.HashMap;
import java.util.Map;

public class ObjPropHandlerFactory {
    private Map<Class, Class<? extends ObjPropHandler>> handlerMap;

    public static final String KEY_ROLE_INFO = "ROLE_INFO";

    public ObjPropHandlerFactory() {
        this.init();
    }

    private void init() {
        this.handlerMap = new HashMap() {{
            put(RoleProp.class, RolePropHandler.class);
            put(MonsterProp.class, MonsterPropHandler.class);
        }};
    }

    public ObjPropHandler getHandler(Class clz, Map<String, Object> handlerParam) {
        Class handlerClz = handlerMap.get(clz);
        if (handlerClz != null) {
            Object handler = ReflectUtil.newInstance(handlerClz, handlerParam);
            return (ObjPropHandler) handler;
        }
        return null;
    }

    public ObjPropHandler getHandler(Class clz) {
        Class handlerClz = handlerMap.get(clz);
        if (handlerClz != null) {
            Object handler = ReflectUtil.newInstance(handlerClz);
            return (ObjPropHandler) handler;
        }
        return null;
    }
}
